package branch.feature.gaode_map.pathsmooth

import android.content.res.AssetManager
import com.amap.api.maps.model.LatLng
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader

class TraceAsset {
    public fun parseLocationsData(assetManager: AssetManager, filepath: String): List<LatLng> {
        val locLists = ArrayList<LatLng>()
        val inputStream: InputStream
        val inputStreamReader: InputStreamReader
        val bufReader: BufferedReader

        try {
            inputStream = assetManager.open(filepath)
            inputStreamReader = InputStreamReader(inputStream)
            bufReader = BufferedReader(inputStreamReader)
            var line: String = ""
            while ((bufReader.readLine().also { line = it }) != null) {
                val strArray = line.split(",")
                val newpoint: LatLng = LatLng(strArray[1].toDouble(), strArray[2].toDouble())

                if (locLists.size == 0 ||
                    newpoint.toString() != locLists.get(locLists.size - 1).toString()
                ) {
                    locLists.add(newpoint)
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        return locLists
    }
}